/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import java.util.ArrayList;
import java.util.Random;

/**
 *
 * @author lenovo
 */
public class Card {
   
    private int[][] cards;
    private int deckSize;
    private Random rand = new Random();
    private int m, n; //m-> global i, n-> global j
    private ArrayList<Integer> distributedCard; //cards that are on the hands of the player
   
    public void initCards(){
        deckSize = 40;
        cards = new int[10][4];
        distributedCard = new ArrayList<Integer>();
        //set every card to -1
        for (int j = 0; j < 4; j++) {
            for (int i = 0; i < 10; i++) {
                cards[i][j] = -1;
            }
        }

        int k = rand.nextInt(10);
//        if (k == 10) {
//            k = 0;
//        }
        for (int j = 0; j < 4; j++) {
            for (int i = 0; i < 10; i++) {

                while (isCardsThere(j, k)) {                                //checks if card is already on deck
                    k = rand.nextInt(10);
//                    if (k == 10) {
//                        k = 0;
//
//                    }
                }
                cards[i][j] = k;
            }
        }
    }
    
    private Boolean isCardsThere(int j, int rand) {//to know if cards in init is already there
        for (int i = 0; i < 10; i++) {
            if (cards[i][j] == rand) {
                return true;
            }
        }
        return false;
    }
    
    public int getACard(){
        m=rand.nextInt(10);                                                 //to know if the cards out of the deck
        n=rand.nextInt(4);
       while(cards[m][n]==-1){
            m=rand.nextInt(10);
            n=rand.nextInt(4);
       }
       distributedCard.add(cards[m][n]);
       deckSize--;
       return cards[m][n];
    }
    
    public ArrayList getDistributedCard(){
        return distributedCard;
    }
    
    public void removeFromDeck(){                           //to remove the card once its taken 
        cards[m][n]=-1;        
    }
    public int getDeckSize(){
        return deckSize;
    }
    public void traverse(){                                                //just print deck of cards
        for(int j=0; j<4; j++){ for(int i=0; i<10; i++)
         System.out.print(cards[i][j]); System.out.println("");
        }
    }

    /**
     * @return the m
     */
    public int getM() {                                                        // the row of the random card
        return m;
    }

    /**
     * @return the n
     */
    public int getN() {                                                         //the column of the random card
        return n;
    }

    /**
     * @param n the n to set
     */
    public void setN(int n) {
        this.n = n;
    }
 
}
